﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Threading;

namespace GlobalRadar.UI
{
    public partial class AppStatusBar : UserControl
    {
        //Thread wait;
        Popup myPopup;
        //bool remove = false;
        public AppStatusBar()
        {
            InitializeComponent();
            myPopup = new Popup();
            myPopup.Child = this;
            OutStatus.Completed += (s, args) =>
            {
                myPopup.IsOpen = false;
            };
        }
        public void ShowPopup(string StatusText)
        {
            SetStatus(StatusText);
            myPopup.IsOpen = true;
            ShowStatus.Begin();
        }
        public void Remove()
        {
            myPopup.IsOpen = false;
        }
        public void Abort()
        {
            OutStatus.Begin();
        }
        //public void ShowPopup(string StatusText,int timer)
        //{
        //    remove = false;
        //    SetStatus(StatusText);
        //    myPopup.IsOpen = true;
        //    Show(timer);
        //}
        //public void ShowPopup(string StatusText)
        //{
        //    remove = false;
        //    SetStatus(StatusText);
        //    myPopup.IsOpen = true;
        //    Show();
        //}
        //public void RemovePopup()
        //{
        //    remove = true;
        //    myPopup.IsOpen = false;
        //    Abort();
        //}
        //public void Show(int timer)
        //{
        //    ShowStatus.Begin();

        //    ShowStatus.Completed += (s, args) =>
        //    {
        //        createWaiting(timer);
        //    };
        //}
        //public void Show()
        //{
        //    remove = false;

        //    ShowStatus.Begin();

        //    ShowStatus.Completed += (s, args) =>
        //    {
        //        wait = new Thread((ThreadStart)delegate()
        //        {
        //            while (!remove)
        //            {
        //                Thread.Sleep(500);
        //            }
        //            Dispatcher.BeginInvoke(() =>Abort());
        //        });
        //        wait.Start();
        //    };
        //}
        //private void createWaiting(int timer)
        //{
        //    wait = new Thread((ThreadStart)delegate()
        //    {
        //        Thread.Sleep(timer);
        //        Dispatcher.BeginInvoke(() => Abort());
        //    });
        //    wait.Start();
        //}
        //public void Abort()
        //{
        //    remove = true;
        //    OutStatus.Begin();
        //    if (wait != null && wait.ThreadState==ThreadState.Running)
        //    {
        //        wait.Abort();
        //    }
        //}
        public void SetStatus(string text)
        {
            this.textBlock1.Text = text;
        }
    }
}
